#ifndef game_image_h
#define game_image_h

namespace image {
    class Image;

    // A Draw object can be used to draw an image. It should be
    // created from the draw() method of the image.
    // To actually draw the object, the draw() method of this object
    // should be called.
    //
    // Basic use: my_img->draw(10, 10).draw();
    // Rotated use: my_img->draw(10, 10).rotated(CONST_PI/3).draw();
    class Draw {
    public:
        // Cause draw() to draw the image rotated by r_ radians.
        Draw &rotated(double theta) { r_ = theta; return *this; }
        // Actually draw the object.
        void draw();
    private:
        friend class Image;
        Draw(Image *image, double x, double y) : image_(image), x_(x), y_(y), r_(0) {}
        Image *image_;
        double x_, y_, r_;
    };
        
    class Image {
    public:
        // Load an image from the resource directory.
        static Image *Load(const char*filename);
        // width and height of the texture.
        int width() const { return width_; }
        int height() const { return height_; }
        // Bind the image to GL_TEXTURE_2D.
        void Bind2D();
        // Return an object that can be used to draw the texture onto
        // the screen. It will be centered at (x, y).
        Draw draw(double x, double y) { return Draw(this, x, y); }
    private:
        int width_, height_, channels_;
        unsigned char *data_;
        int i;
        Image();
        ~Image();
    };
}  // namespace image

#endif
